var view =  {
    bookSearch: function (id,url,data) {
        layui.use(['layer', 'form', 'jquery', 'table'],function(){
            var layer = layui.layer
                ,form = layui.form
                ,$= layui.$
                ,table=layui.table;

            var type="1";
            $.ajax({
                type:"post",
                url:url,
                data:data,
                dataType:"json",
                async:false,
                contentType : "application/json; charset=utf-8",
                success: function(res){
                    if(type=="1"){
                        debugger;
                        //列表查询
                        if (res.data) {
                            table.render({
                                elem: "#book-table",
                                data: res.data,
                                skin: 'line',
                      //          toolbar: '#user-toolbar', 工具栏
                      //           defaultToolbar: [{
                      //               layEvent: 'refresh',
                      //               icon: 'layui-icon-refresh',
                      //           }, 'filter', 'print', 'exports'],
                                cols: [
                                    [
                                         {field: 'bookName', title: '书名', width: 180,templet: bookLink}
                                        , {field: 'bookAuthor', title: '作者', width: 180}
                                        , {field: 'book_kind', title: '类别', width: 177}
                                        , {field: 'book_state', title: '连载状态', width: 180}
                                        , {field: 'bookLastChapter', title: '最新章节', width: 280,templet: lastLink}
                                        , {field: 'sourceName', title: '来源', width: 180}
                                    ] //设置表头
                                ],
                                done: function (res, curr, count) {
                                $("table").css("width","100%");
                            },
                                parseData: function (data) { //res 即为原始返回的数据
                                    return {
                                        "code": 0, //解析接口状态
                                        "msg": "", //解析提示文本
                                        "count": 100, //解析数据长度
                                        "data": data //解析数据列表
                                    }
                                }
                                , limit: 15
                                , limits: [15, 50, 100]
                                , page: true //开启分页
                            });
                        }
                    }else{
                        //图表查询
                        $(".item").remove();
                        var rs = res.data;
                        if(rs.length>0){
                            for (var i=0;i<rs.length;i++) {
                                debugger;
                                var rsdate = rs[i];
                                var div="<div class='item'>"+
                                    "<div><div class='pic_item'><img src="+rsdate.bookCover+" onclick='test("+JSON.stringify(rsdate)+")'  " + " onerror=\"javascript:this.src='/img/magic/nocover.jpg';this.onerror = null\" style='width:110px;height:150px;'></div></div>"+
                                    "<div class='result-game-item-detail'>" +
                                    "<h3 class='item-title'><a  onclick='test("+JSON.stringify(rsdate)+")' class='title-link'><span>"+rsdate.bookName+"</span><span></span></a></h3>" +
                                    "<p class='result-game-item-desc'>"+rsdate.bookDuce+"</p>"+"</div>"+
                                    "<div class='item-detail'>" +
                                    "<p class='result-game-item-info-tag'><span class='result-game-item-info-tag-title preBold'>来源：</span><span>"+rsdate.sourceName+"</span></p>" +
                                    "<p class='result-game-item-info-tag'><span class='result-game-item-info-tag-title preBold'>作者：</span><span>"+rsdate.bookAuthor+"</span></p>" +
                                    "<p class='result-game-item-info-tag'><span class='result-game-item-info-tag-title preBold'>类型：</span><span>"+rsdate.bookKind+"</span></p>" +
                                    "<p class='result-game-item-info-tag'><span class='result-game-item-info-tag-title preBold'>更新时间：</span><span>"+rsdate.bookLastChapterDate+"</span></p>" +
                                    "<p class='result-game-item-info-tag'><span class='result-game-item-info-tag-title preBold'>最新章节：</span><span><a onclick='chapterContextfowdard("+JSON.stringify(rsdate)+")'>"+rsdate.bookLastChapter+"</a></span></p>" +
                                    "</div>"+
                                    "</div>";
                                $(".search_book_list").append(div);
                            }
                        }else{
                            div ="<p>未搜索到相关信息</p>"
                        }
                    }
                }
            });

            table.on('tool(book-table)', function(obj) {
                if (obj.event === 'remove') {
                    window.remove(obj);
                } else if (obj.event === 'edit') {
                    window.edit(obj);
                }else if (obj.event === 'bklikn'){
                    active.bklikn(obj);
                }else if(obj.event ==='lastLink'){
                    active.lastLink(obj);
                }
            });

        })

        function bookLink(d){
            let addLink = d.bookName;
            if (addLink.length > 0) {
                return '<a class="layui-table-link" href="javascript:void(0);"  lay-event="bklikn">' + d.bookName + '</a>';
            }
        }
        function lastLink(d){
            let lastLink = d.bookName;
            if (lastLink.length > 0) {
                return '<a class="layui-table-link" href="javascript:void(0);"  lay-event="lastLink">' + d.bookLastChapter + '</a>';
            }

        }
        var active = {
            bklikn:function (obj){
                var data = obj.data;
                ds = data;
                //iframe窗
                forward('/forward/book/pageBook/bookChapterList',data)
            },
            lastLink : function (obj) {
                var data = obj.data;
                data.chapterName=data.bookLastChapter;
                data.chapterUrl=data.bookLastChapterUrl;
                debugger
                forward('/forward/book/pageBook/bookRead',data);
 /*               $.ajax({
                    type:"post",
                    url:'/BookAdmin/queryChapter',
                    data:JSON.stringify(data),
                    dataType:"json",
                    async:false,
                    contentType : "application/json; charset=utf-8",
                    success: function(res) {
                        debugger
                        chapterInfo =res.data;
                        layer.open({
                            title:chapterInfo.chapterName,
                            type: 2,
                            content: '/forward/book/admin/bookRead',
                            data:chapterInfo,
                            area: ['70%', '95%'],
                            shadeClose: true,
                            maxmin: false
                        });
                    }
                })*/
            }
        }


    }



}

